//package com.plian.system.service.sys.warning.impl;
//
//import cn.hutool.core.util.ReUtil;
//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
//import com.baomidou.mybatisplus.core.toolkit.StringPool;
//import com.baomidou.mybatisplus.core.toolkit.Wrappers;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import com.plian.Tools.BigDecimalUtil;
//import com.plian.Tools.CollectionUtil;
//import com.plian.Tools.DateUtil;
//import com.plian.Tools.StringUtil;
//import com.plian.Tools.operation.OperationExpressionUtil;
//import com.plian.system.constant.sys.WarningValueTypeConstant;
//import com.plian.system.dao.sys.excel.AutoExcelDao;
//import com.plian.system.entity.fr.adjustment.Adjustment;
//import com.plian.system.entity.fr.adjustment.AdjustmentLink;
//import com.plian.system.entity.fr.adjustment.AdjustmentValue;
//import com.plian.system.entity.fr.authorize.Authorize;
//import com.plian.system.entity.fr.authorize.AuthorizeLink;
//import com.plian.system.entity.fr.authorize.AuthorizeValue;
//import com.plian.system.entity.fr.bulletin.BulletinValue;
//import com.plian.system.entity.fr.bulletin.NewBulletin;
//import com.plian.system.entity.fr.payrolladjustment.PayrollAdjustment;
//import com.plian.system.entity.fr.payrolladjustment.PayrollAdjustmentLink;
//import com.plian.system.entity.fr.payrolladjustment.PayrollAdjustmentValue;
//import com.plian.system.entity.fr.report.Report;
//import com.plian.system.entity.fr.report.ReportColumnValue;
//import com.plian.system.entity.fr.report.ReportLink;
//import com.plian.system.entity.sys.excel.AutoExcel;
//import com.plian.system.entity.sys.warning.WarningFactor;
//import com.plian.system.entity.sys.warning.WarningFactorExtension;
//import com.plian.system.entity.sys.warning.WarningFactorValue;
//import com.plian.system.mapper.sys.warning.WarningFactorValueMapper;
//import com.plian.system.service.fr.adjustment.IAdjustmentColumnService;
//import com.plian.system.service.fr.adjustment.IAdjustmentService;
//import com.plian.system.service.fr.adjustment.IAdjustmentValueService;
//import com.plian.system.service.fr.authorize.IAuthorizeColumnService;
//import com.plian.system.service.fr.authorize.IAuthorizeService;
//import com.plian.system.service.fr.authorize.IAuthorizeValueService;
//import com.plian.system.service.fr.bulletin.INewBulletinService;
//import com.plian.system.service.fr.payrolladjustment.IPayrollAdjustmentColumnService;
//import com.plian.system.service.fr.payrolladjustment.IPayrollAdjustmentService;
//import com.plian.system.service.fr.payrolladjustment.IPayrollAdjustmentValueService;
//import com.plian.system.service.fr.report.IReportColumnService;
//import com.plian.system.service.fr.report.IReportColumnValueService;
//import com.plian.system.service.fr.report.IReportService;
//import com.plian.system.service.sys.excel.IAutoExcelService;
//import com.plian.system.service.sys.warning.IWarningFactorExtensionService;
//import com.plian.system.service.sys.warning.IWarningFactorService;
//import com.plian.system.service.sys.warning.IWarningFactorValueService;
//import com.plian.system.vo.sys.excel.AutoExcelValueVO;
//import lombok.AllArgsConstructor;
//import org.springframework.stereotype.Service;
//
//import java.math.BigDecimal;
//import java.util.*;
//import java.util.stream.Collectors;
//
//import static com.plian.system.constant.sys.TableTypeCode.MERGE_TABLE_TYPE;
//import static com.plian.system.constant.sys.WarningBulletinValueTypeConstant.*;
//import static com.plian.system.constant.sys.WarningConfigConstant.*;
//import static com.plian.system.constant.sys.WarningDataSourceConstant.*;
//import static com.plian.system.constant.sys.WarningValueTypeConstant.*;
//
//@Service
//@AllArgsConstructor
//public class WarningFactorValueServiceImpl extends ServiceImpl<WarningFactorValueMapper, WarningFactorValue> implements IWarningFactorValueService {
//
//    private IWarningFactorService warningFactorService;
//
//    private IWarningFactorExtensionService warningFactorExtensionService;
//
//    private INewBulletinService newBulletinService;
//
//    private IReportService reportService;
//
//    private IReportColumnService reportColumnService;
//
//    private IReportColumnValueService reportColumnValueService;
//
//    private IPayrollAdjustmentService payrollAdjustmentService;
//
//    private IPayrollAdjustmentColumnService payrollAdjustmentColumnService;
//
//    private IPayrollAdjustmentValueService payrollAdjustmentValueService;
//
//    private IAuthorizeService authorizeService;
//
//    private IAuthorizeColumnService authorizeColumnService;
//
//    private IAuthorizeValueService authorizeValueService;
//
//    private IAdjustmentService adjustmentService;
//
//    private IAdjustmentColumnService adjustmentColumnService;
//
//    private IAdjustmentValueService adjustmentValueService;
//
//    private IAutoExcelService autoExcelService;
//
//    private AutoExcelDao autoExcelDao;
//
//    //特殊取数正则
//    private final String SPECIAL_REGULAR = "@{1}\\{[A-Za-z0-9_$]*\\}";
//
//
//
//    @Override
//    public void updateValueByYear(int year) {
//        List<WarningFactorExtension> factorExtensionList = warningFactorExtensionService.list(Wrappers.<WarningFactorExtension>lambdaQuery()
//                .eq(WarningFactorExtension::getFactorYear, year));
//        List<WarningFactor> warningFactorList = warningFactorService.list();
//        List<WarningFactorValue> warningFactorValues = getValue(year, factorExtensionList, warningFactorList);
//        remove(Wrappers.<WarningFactorValue>lambdaQuery().eq(WarningFactorValue::getYear, year));
//        if (CollectionUtil.isNotEmpty(warningFactorValues)){
//            saveBatch(warningFactorValues);
//        }
//    }
//
//    @Override
//    public void updateValueByFactorIds(List<Long> factorIds, int year) {
//        List<WarningFactorExtension> factorExtensionList = warningFactorExtensionService.list(Wrappers.<WarningFactorExtension>lambdaQuery()
//                .in(WarningFactorExtension::getFactorId, factorIds)
//                .eq(WarningFactorExtension::getFactorYear, year));
//        List<WarningFactor> warningFactorList = warningFactorService.listByIds(factorIds);
//        List<WarningFactorValue> warningFactorValues = getValue(year, factorExtensionList, warningFactorList);
//        remove(Wrappers.<WarningFactorValue>lambdaQuery().eq(WarningFactorValue::getYear, year).in(WarningFactorValue::getFactorId, factorIds));
//        if (CollectionUtil.isNotEmpty(warningFactorValues)){
//            saveBatch(warningFactorValues);
//        }
//    }
//
//    private List<WarningFactorValue> getValue(int year, List<WarningFactorExtension> factorExtensionList, List<WarningFactor> warningFactorList){
//        Map<Long, WarningFactorExtension> factorExtensionMap = factorExtensionList.stream()
//                .filter(warningFactorExtension -> warningFactorExtension.getValueType() == 2)
//                .collect(Collectors.toMap(WarningFactorExtension::getFactorId, warningFactorExtension -> warningFactorExtension));
//        Map<Integer, List<WarningFactor>> dataSourceMap = warningFactorList.stream().collect(Collectors.groupingBy(WarningFactor::getDataSource));
//        List<WarningFactorValue> warningFactorValues = new ArrayList<>();
//        for (Integer dataSource : dataSourceMap.keySet()) {
//            List<WarningFactor> factors = dataSourceMap.get(dataSource);
//            switch (dataSource) {
//                case BULLETIN:
//                    // 快报
//                    warningFactorValues.addAll(warningFactorToBulletinValue(year, factors, factorExtensionMap));
//                    break;
//                case BUDGET:
//                    // 预算
//                    warningFactorValues.addAll(warningFactorToBudgetValue(year, factors, factorExtensionMap));
//                    break;
//                case SALARY_BUDGET:
//                    // 工资预算
//                    warningFactorValues.addAll(warningFactorToPayrollValue(year, factors, factorExtensionMap));
//                    break;
//                case APPROVAL:
//                    // 审定
//                    warningFactorValues.addAll(warningFactorToAuthorizeValue(year, factors, factorExtensionMap));
//                    break;
//                case BUDGET_ADJUSTMENT:
//                    // 预算调整
//                    warningFactorValues.addAll(warningFactorToAdjustmentValue(year, factors, factorExtensionMap));
//                    break;
//                case EXCEL:
//                    // 自定义表格
//                    warningFactorValues.addAll(warningFactorToAutoExcelValue(year, factors, factorExtensionMap));
//                    break;
//                case REGULAR_TABLE:
//                    // 常规表
//                    // TODO
//                    break;
//            }
//        }
//
//        if (CollectionUtil.isNotEmpty(warningFactorValues)){
//            List<WarningFactorExtension> formulaList = factorExtensionList.stream()
//                    .filter(warningFactorExtension -> warningFactorExtension.getValueType() == 1).collect(Collectors.toList());
//            Map<Long, WarningFactor> factorIdMap = warningFactorList.stream().collect(Collectors.toMap(WarningFactor::getId, warningFactor -> warningFactor));
//            Map<String, List<WarningFactorValue>> valueOrgSummaryCodeMap = warningFactorValues.stream().filter(warningFactorValue -> warningFactorValue.getSummaryCode() != null)
//                    .collect(Collectors.groupingBy(warningFactorValue -> warningFactorValue.getOrgId() + StringPool.DASH + warningFactorValue.getIsGroup() + StringPool.DASH + warningFactorValue.getSummaryCode()));
//            if (CollectionUtil.isNotEmpty(valueOrgSummaryCodeMap)){
//                warningFactorValues.addAll(formulaToValueList(year, factorIdMap, formulaList , valueOrgSummaryCodeMap, true));
//            }
//            Map<String, List<WarningFactorValue>> valueOrgMap = warningFactorValues.stream().filter(warningFactorValue -> warningFactorValue.getSummaryCode() == null)
//                    .collect(Collectors.groupingBy(warningFactorValue -> warningFactorValue.getOrgId() + StringPool.DASH + warningFactorValue.getIsGroup()));
//            if (CollectionUtil.isNotEmpty(valueOrgMap)){
//                warningFactorValues.addAll(formulaToValueList(year, factorIdMap, formulaList , valueOrgMap, false));
//            }
//        }
//        return warningFactorValues;
//    }
//
//    /**
//     * 快报数据转换
//     *
//     * @param year
//     * @param factors
//     * @param factorExtensionMap
//     * @return
//     */
//    private List<WarningFactorValue> warningFactorToBulletinValue(int year, List<WarningFactor> factors, Map<Long, WarningFactorExtension> factorExtensionMap) {
//        String lastYearMaxMonth = year - 1 + StringPool.DASH + "12";
//        List<NewBulletin> newBulletinList = newBulletinService.findFinishByYear(year);
//        List<NewBulletin> lastYearMaxMonthBulletin = newBulletinService.findFinishByReportTime(lastYearMaxMonth);
//        List<WarningFactorValue> warningFactorValues = new ArrayList<>();
//        for (WarningFactor factor : factors) {
//            if (!factorExtensionMap.containsKey(factor.getId())) {
//                continue;
//            }
//            WarningFactorExtension factorExtension = factorExtensionMap.get(factor.getId());
//            if (factorExtension.getBulletinValueType() == LAST_YEAR_MAX_AMOUNT) {
//                // 去年年末
//                for (NewBulletin newBulletin : lastYearMaxMonthBulletin) {
//                    List<BulletinValue> bulletinValues = newBulletin.getBulletinValues();
//                    Map<String, BulletinValue> valueMap = bulletinValues.stream().collect(Collectors.toMap(BulletinValue::getTypeCode, bulletinValue -> bulletinValue));
//                    if (valueMap.containsKey(factorExtension.getBulletinCode())) {
//                        continue;
//                    }
//                    BulletinValue value = valueMap.get(factorExtension.getBulletinCode());
//                    for (int i = 1; i <= 12; i++) {
//                        WarningFactorValue warningFactorValue = new WarningFactorValue();
//                        warningFactorValue.setFactorId(factor.getId());
//                        warningFactorValue.setFactorCode(factor.getFactorCode());
//                        warningFactorValue.setYear(year);
//                        warningFactorValue.setMonth(i);
//                        warningFactorValue.setOrgId(newBulletin.getOrgId());
//                        warningFactorValue.setIsGroup(newBulletin.getTableTypeCode().equals(MERGE_TABLE_TYPE) ? 1 : 0);
//                        warningFactorValue.setSummaryCode(Integer.valueOf(newBulletin.getSummaryCode()));
//                        warningFactorValues.add(warningFactorValue);
//                        warningFactorValue.setValue(value.getYearAmount());
//                        warningFactorValue.setValueType(MONTH_VALUE);
//                        warningFactorValues.add(warningFactorValue);
//                    }
//                }
//                continue;
//            }
//            for (NewBulletin newBulletin : newBulletinList) {
//                List<BulletinValue> bulletinValues = newBulletin.getBulletinValues();
//                Map<String, BulletinValue> valueMap = bulletinValues.stream().collect(Collectors.toMap(BulletinValue::getTypeCode, bulletinValue -> bulletinValue));
//                if (!valueMap.containsKey(factorExtension.getBulletinCode())) {
//                    continue;
//                }
//                String reportTimeStr = DateUtil.format(newBulletin.getReportTime(), DateUtil.PATTERN_MONTH);
//                WarningFactorValue warningFactorValue = new WarningFactorValue();
//                warningFactorValue.setFactorId(factor.getId());
//                warningFactorValue.setFactorCode(factor.getFactorCode());
//                warningFactorValue.setYear(year);
//                warningFactorValue.setMonth(Integer.valueOf(reportTimeStr.split(StringPool.DASH)[1]));
//                warningFactorValue.setOrgId(newBulletin.getOrgId());
//                warningFactorValue.setIsGroup(newBulletin.getTableTypeCode().equals(MERGE_TABLE_TYPE) ? 1 : 0);
//                warningFactorValue.setSummaryCode(Integer.valueOf(newBulletin.getSummaryCode()));
//                warningFactorValue.setValueType(MONTH_VALUE);
//                BulletinValue value = valueMap.get(factorExtension.getBulletinCode());
//                switch (factorExtension.getBulletinValueType()) {
//                    case MONTH_AMOUNT:
//                        // 本月
//                        warningFactorValue.setValue(value.getMonthAmount());
//                        warningFactorValues.add(warningFactorValue);
//                        break;
//                    case YEAR_AMOUNT:
//                        // 本年累计
//                        warningFactorValue.setValue(value.getYearAmount());
//                        warningFactorValues.add(warningFactorValue);
//                        break;
//                    case LAST_YEAR_MONTH_AMOUNT:
//                        // 去年同期
//                        warningFactorValue.setValue(value.getLastYearMonthAmount());
//                        warningFactorValues.add(warningFactorValue);
//                        break;
//                }
//            }
//        }
//        return warningFactorValues;
//    }
//
//    private List<WarningFactorValue> warningFactorToBudgetValue(int year, List<WarningFactor> factors, Map<Long, WarningFactorExtension> factorExtensionMap) {
//        List<Report> reportList = reportService.findFinishByYear(year);
//        if (CollectionUtil.isEmpty(reportList)) {
//            return Collections.emptyList();
//        }
//        List<WarningFactorValue> warningFactorValues = new ArrayList<>();
//        for (WarningFactor factor : factors) {
//            if (!factorExtensionMap.containsKey(factor.getId())) {
//                continue;
//            }
//            WarningFactorExtension factorExtension = factorExtensionMap.get(factor.getId());
//            String columnId = reportColumnService.columnNumberToColumnId(factorExtension.getColumnNumber(), factorExtension.getSheetId());
//            if (StringUtil.isBlank(columnId)) {
//                continue;
//            }
//            for (Report report : reportList) {
//                Map<String, ReportLink> reportLinkMap = report.getReportLinkList().stream().collect(Collectors.toMap(ReportLink::getOrgId, reportLink -> reportLink));
//                if (!reportLinkMap.containsKey(factorExtension.getSheetId())) {
//                    continue;
//                }
//                WarningFactorValue warningFactorValue = new WarningFactorValue();
//                ReportColumnValue columnValue = reportColumnValueService.findValueByLinkId(reportLinkMap.get(factorExtension.getSheetId()).getLinkId(), factorExtension.getLineNumber(), columnId);
//                if (columnValue == null) {
//                    continue;
//                }
//                warningFactorValue.setFactorId(factor.getId());
//                warningFactorValue.setFactorCode(factor.getFactorCode());
//                warningFactorValue.setYear(year);
//                warningFactorValue.setMonth(0);
//                warningFactorValue.setOrgId(report.getUnit());
//                warningFactorValue.setIsGroup(report.getFhTableTypeCode().equals(MERGE_TABLE_TYPE) ? 1 : 0);
//                warningFactorValue.setSummaryCode(Integer.valueOf(report.getSummaryCode()));
//                warningFactorValue.setValue(BigDecimalUtil.toBigdecimal(columnValue.getReplyValue()));
//                warningFactorValue.setValueType(YEAR_VALUE);
//                warningFactorValues.add(warningFactorValue);
//            }
//        }
//        return warningFactorValues;
//    }
//
//    private List<WarningFactorValue> warningFactorToPayrollValue(int year, List<WarningFactor> factors, Map<Long, WarningFactorExtension> factorExtensionMap) {
//        List<PayrollAdjustment> payrollAdjustmentList = payrollAdjustmentService.findFinishByYear(year);
//        if (CollectionUtil.isEmpty(payrollAdjustmentList)) {
//            return Collections.emptyList();
//        }
//        List<WarningFactorValue> warningFactorValues = new ArrayList<>();
//        for (WarningFactor factor : factors) {
//            if (!factorExtensionMap.containsKey(factor.getId())) {
//                continue;
//            }
//            WarningFactorExtension factorExtension = factorExtensionMap.get(factor.getId());
//            String columnId = payrollAdjustmentColumnService.columnNumberToColumnId(factorExtension.getColumnNumber(), factorExtension.getSheetId());
//            if (StringUtil.isBlank(columnId)) {
//                continue;
//            }
//            for (PayrollAdjustment payrollAdjustment : payrollAdjustmentList) {
//                Map<String, PayrollAdjustmentLink> linkMap = payrollAdjustment.getLinkList().stream().collect(Collectors.toMap(PayrollAdjustmentLink::getOrgId, reportLink -> reportLink));
//                if (!linkMap.containsKey(factorExtension.getSheetId())) {
//                    continue;
//                }
//                WarningFactorValue warningFactorValue = new WarningFactorValue();
//                PayrollAdjustmentValue columnValue = payrollAdjustmentValueService.findValueByLinkId(linkMap.get(factorExtension.getSheetId()).getLinkId(), factorExtension.getLineNumber(), columnId);
//                if (columnValue == null) {
//                    continue;
//                }
//                warningFactorValue.setFactorId(factor.getId());
//                warningFactorValue.setFactorCode(factor.getFactorCode());
//                warningFactorValue.setYear(year);
//                warningFactorValue.setMonth(0);
//                warningFactorValue.setOrgId(payrollAdjustment.getUnit());
//                warningFactorValue.setIsGroup(payrollAdjustment.getFhTableTypeCode().equals(MERGE_TABLE_TYPE) ? 1 : 0);
//                warningFactorValue.setSummaryCode(Integer.valueOf(payrollAdjustment.getSummaryCode()));
//                warningFactorValue.setValue(BigDecimalUtil.toBigdecimal(columnValue.getReplyValue()));
//                warningFactorValue.setValueType(YEAR_VALUE);
//                warningFactorValues.add(warningFactorValue);
//            }
//        }
//        return warningFactorValues;
//    }
//
//    private List<WarningFactorValue> warningFactorToAuthorizeValue(int year, List<WarningFactor> factors, Map<Long, WarningFactorExtension> factorExtensionMap) {
//        List<Authorize> authorizeList = authorizeService.findFinishByYear(year);
//        if (CollectionUtil.isEmpty(authorizeList)) {
//            return Collections.emptyList();
//        }
//        List<WarningFactorValue> warningFactorValues = new ArrayList<>();
//        for (WarningFactor factor : factors) {
//            if (!factorExtensionMap.containsKey(factor.getId())) {
//                continue;
//            }
//            WarningFactorExtension factorExtension = factorExtensionMap.get(factor.getId());
//            String columnId = authorizeColumnService.columnNumberToColumnId(factorExtension.getColumnNumber(), factorExtension.getSheetId());
//            if (StringUtil.isBlank(columnId)) {
//                continue;
//            }
//            for (Authorize authorize : authorizeList) {
//                Map<String, AuthorizeLink> linkMap = authorize.getLinkList().stream().collect(Collectors.toMap(AuthorizeLink::getOrgId, reportLink -> reportLink));
//                if (!linkMap.containsKey(factorExtension.getSheetId())) {
//                    continue;
//                }
//                WarningFactorValue warningFactorValue = new WarningFactorValue();
//                AuthorizeValue authorizeValue = authorizeValueService.findValueByLinkId(linkMap.get(factorExtension.getSheetId()).getLinkId(), factorExtension.getLineNumber(), columnId);
//                if (authorizeValue == null) {
//                    continue;
//                }
//                warningFactorValue.setFactorId(factor.getId());
//                warningFactorValue.setFactorCode(factor.getFactorCode());
//                warningFactorValue.setYear(year);
//                warningFactorValue.setMonth(0);
//                warningFactorValue.setOrgId(authorize.getUnit());
//                warningFactorValue.setIsGroup(authorize.getFhTableTypeCode().equals(MERGE_TABLE_TYPE) ? 1 : 0);
//                warningFactorValue.setSummaryCode(Integer.valueOf(authorize.getSummaryCode()));
//                warningFactorValue.setValue(BigDecimalUtil.toBigdecimal(authorizeValue.getReplyValue()));
//                warningFactorValue.setValueType(YEAR_VALUE);
//                warningFactorValues.add(warningFactorValue);
//            }
//        }
//        return warningFactorValues;
//    }
//
//    private List<WarningFactorValue> warningFactorToAdjustmentValue(int year, List<WarningFactor> factors, Map<Long, WarningFactorExtension> factorExtensionMap) {
//        List<Adjustment> adjustmentList = adjustmentService.findFinishByYear(year);
//        if (CollectionUtil.isEmpty(adjustmentList)) {
//            return Collections.emptyList();
//        }
//        List<WarningFactorValue> warningFactorValues = new ArrayList<>();
//        for (WarningFactor factor : factors) {
//            if (!factorExtensionMap.containsKey(factor.getId())) {
//                continue;
//            }
//            WarningFactorExtension factorExtension = factorExtensionMap.get(factor.getId());
//            String columnId = adjustmentColumnService.columnNumberToColumnId(factorExtension.getColumnNumber(), factorExtension.getSheetId());
//            if (StringUtil.isBlank(columnId)) {
//                continue;
//            }
//            for (Adjustment adjustment : adjustmentList) {
//                Map<String, AdjustmentLink> linkMap = adjustment.getLinkList().stream().collect(Collectors.toMap(AdjustmentLink::getOrgId, reportLink -> reportLink));
//                if (!linkMap.containsKey(factorExtension.getSheetId())) {
//                    continue;
//                }
//                WarningFactorValue warningFactorValue = new WarningFactorValue();
//                AdjustmentValue adjustmentValue = adjustmentValueService.findValueByLinkId(linkMap.get(factorExtension.getSheetId()).getLinkId(), factorExtension.getLineNumber(), columnId);
//                if (adjustmentValue == null) {
//                    continue;
//                }
//                warningFactorValue.setFactorId(factor.getId());
//                warningFactorValue.setFactorCode(factor.getFactorCode());
//                warningFactorValue.setYear(year);
//                warningFactorValue.setMonth(0);
//                warningFactorValue.setOrgId(adjustment.getUnit());
//                warningFactorValue.setIsGroup(adjustment.getFhTableTypeCode().equals(MERGE_TABLE_TYPE) ? 1 : 0);
//                warningFactorValue.setSummaryCode(Integer.valueOf(adjustment.getSummaryCode()));
//                warningFactorValue.setValue(BigDecimalUtil.toBigdecimal(adjustmentValue.getReplyValue()));
//                warningFactorValue.setValueType(YEAR_VALUE);
//                warningFactorValues.add(warningFactorValue);
//            }
//        }
//        return warningFactorValues;
//    }
//
//    private List<WarningFactorValue> warningFactorToAutoExcelValue(int year, List<WarningFactor> factors, Map<Long, WarningFactorExtension> factorExtensionMap) {
//        List<WarningFactorValue> warningFactorValues = new ArrayList<>();
//        for (WarningFactor factor : factors){
//            if (!factorExtensionMap.containsKey(factor.getId())) {
//                continue;
//            }
//            AutoExcel autoExcel = autoExcelService.findByCodeAndYear(factor.getExcelCode(), year);
//            if (autoExcel == null){
//                continue;
//            }
//
//            WarningFactorExtension factorExtension = factorExtensionMap.get(factor.getId());
//            List<AutoExcelValueVO> autoExcelValueVOList = null;
//            try {
//                autoExcelValueVOList = autoExcelDao.getFinishData(autoExcel,factorExtension.getSheetId(), year, factorExtension.getColumnNumber(), factorExtension.getLineNumber());
//            }catch (Exception e){
//                log.error("获取excel数据失败", e);
//                continue;
//            }
//            if (CollectionUtil.isEmpty(autoExcelValueVOList)){
//                continue;
//            }
//            for (AutoExcelValueVO autoExcelValueVO : autoExcelValueVOList){
//                WarningFactorValue warningFactorValue = new WarningFactorValue();
//                warningFactorValue.setFactorId(factor.getId());
//                warningFactorValue.setFactorCode(factor.getFactorCode());
//                warningFactorValue.setYear(year);
//                int month = Integer.valueOf(autoExcelValueVO.getReportTime().split(StringPool.DASH)[1]);
//                if (autoExcel.getFillType() == 0){
//                    warningFactorValue.setMonth(month);
//                    warningFactorValue.setValueType(MONTH_VALUE);
//                }else if (autoExcel.getFillType() == 1){
//                    warningFactorValue.setMonth(month);
//                    warningFactorValue.setQuarter(monthToQuarter(month));
//                    warningFactorValue.setValueType(WarningValueTypeConstant.QUARTER_VALUE);
//                }else {
//                    warningFactorValue.setMonth(0);
//                    warningFactorValue.setValueType(YEAR_VALUE);
//                }
//
//                warningFactorValue.setOrgId(autoExcelValueVO.getOrgId());
//                warningFactorValue.setIsGroup(0);
//                warningFactorValue.setValue(autoExcelValueVO.getValue());
//                warningFactorValues.add(warningFactorValue);
//            }
//
//        }
//        return warningFactorValues;
//    }
//
//    private int monthToQuarter(int month){
//        if (month <= 3){
//            return 1;
//        }else if (month <= 6){
//            return 2;
//        }else if (month <= 9){
//            return 3;
//        }else {
//            return 4;
//        }
//    }
//
//    private List<WarningFactorValue> formulaToValueList(int year,Map<Long, WarningFactor> factorIdMap, List<WarningFactorExtension> formulaList,
//                                                     Map<String, List<WarningFactorValue>> valueOrgMap, boolean hasSummaryCode){
//        OperationExpressionUtil operationExpressionUtil = new OperationExpressionUtil();
//        List<WarningFactorValue> warningFactorValues = new ArrayList<>();
//        Map<Long, List<String>> specialCodeMap = new HashMap<>();
//        for (WarningFactorExtension warningFactorExtension : formulaList){
//            if (warningFactorExtension.getFormula().contains(StringPool.AT)){
//                //需要处理的公式
//                String formula = warningFactorExtension.getFormula();
//                List<String> specialList = ReUtil.findAll(SPECIAL_REGULAR, formula, 0, new ArrayList<String>());
//                List<String> tempList = new ArrayList<>();
//                for (String specialStr : specialList){
//                    String tempString = specialStr.substring(2, specialStr.length() - 1);
//                    if (!tempList.contains(tempString)){
//                        tempList.add(tempString);
//                    }
//                    formula = formula.replace(specialStr, tempString);
//                }
//                specialCodeMap.put(warningFactorExtension.getId(), tempList);
//                warningFactorExtension.setFormula(formula);
//            }
//        }
//        for (String key : valueOrgMap.keySet()) {
//            List<WarningFactorValue> orgValueGroupList = valueOrgMap.get(key);
//            String orgId = key.split(StringPool.DASH)[0];
//            Integer isGroup = Integer.valueOf(key.split(StringPool.DASH)[1]);
//            Map<Integer, List<WarningFactorValue>> valueTypeMap = orgValueGroupList.stream().collect(Collectors.groupingBy(WarningFactorValue::getValueType));
//            Map<Integer, List<WarningFactorValue>> quarterValueQuarterMap = valueTypeMap.getOrDefault(QUARTER_VALUE, new ArrayList<>()).stream().collect(Collectors.groupingBy(WarningFactorValue::getQuarter));
//            Map<Integer, List<WarningFactorValue>> monthValueMonthMap = valueTypeMap.getOrDefault(MONTH_VALUE, new ArrayList<>()).stream().collect(Collectors.groupingBy(WarningFactorValue::getMonth));
//            Map<String, BigDecimal> yearValueMap = valueTypeMap.getOrDefault(YEAR_VALUE, new ArrayList<>()).stream().collect(Collectors.toMap(WarningFactorValue::getFactorCode, WarningFactorValue::getValue));
//            for (Integer month : monthValueMonthMap.keySet()){
//                List<WarningFactorValue> monthValueList = monthValueMonthMap.get(month);
//                Map<String, BigDecimal> tempMap = monthValueList.stream().filter(warningFactorValue -> warningFactorValue.getValue() != null)
//                        .collect(Collectors.toMap(WarningFactorValue::getFactorCode, WarningFactorValue::getValue));
//                tempMap.putAll(yearValueMap);
//                int quarter = monthToQuarter(month);
//                if (CollectionUtil.isNotEmpty(quarterValueQuarterMap) && quarterValueQuarterMap.containsKey(quarter)){
//                    tempMap.putAll(quarterValueQuarterMap.get(quarter).stream().collect(Collectors.toMap(WarningFactorValue::getFactorCode, WarningFactorValue::getValue)));
//                }
//                for(WarningFactorExtension warningFactorExtension : formulaList){
//                    WarningFactor factor = factorIdMap.get(warningFactorExtension.getFactorId());
//                    WarningFactorValue warningFactorValue = new WarningFactorValue();
//                    warningFactorValue.setFactorId(factor.getId());
//                    warningFactorValue.setFactorCode(factor.getFactorCode());
//                    warningFactorValue.setYear(year);
//                    warningFactorValue.setMonth(month);
//                    warningFactorValue.setOrgId(orgId);
//                    warningFactorValue.setIsGroup(isGroup);
//                    if (hasSummaryCode){
//                        warningFactorValue.setSummaryCode(Integer.valueOf(key.split(StringPool.DASH)[2]));
//                    }
//
//                    if (specialCodeMap.containsKey(warningFactorExtension.getId())){
//                        List<String> specialCodeList = specialCodeMap.get(warningFactorExtension.getId());
//                        for (String specialCode : specialCodeList){
//                            String[] strings = specialCode.split("\\$");
//                            LambdaQueryWrapper<WarningFactorValue> queryWrapper = Wrappers.<WarningFactorValue>lambdaQuery()
//                                    .eq(WarningFactorValue::getOrgId, orgId)
//                                    .eq(WarningFactorValue::getIsGroup, isGroup);
//                            if (hasSummaryCode){
//                                queryWrapper.eq(WarningFactorValue::getSummaryCode, Integer.valueOf(key.split(StringPool.DASH)[2]));
//                            }
//                            queryWrapper.eq(WarningFactorValue::getFactorCode, strings[1]);
//                            switch (strings[0]){
//                                case LAST_YEAR:
//                                    queryWrapper.eq(WarningFactorValue::getYear, year - 1);
//                                    queryWrapper.eq(WarningFactorValue::getMonth, month);
//                                    break;
//                                case LAST_YEAR_MAX:
//                                    queryWrapper.eq(WarningFactorValue::getYear, year - 1);
//                                    queryWrapper.eq(WarningFactorValue::getMonth, 12);
//                                    break;
//                                case BEFORE_YEAR:
//                                    queryWrapper.eq(WarningFactorValue::getYear, year - 2);
//                                    queryWrapper.eq(WarningFactorValue::getMonth, month);
//                                    break;
//                                case BEFORE_YEAR_MAX:
//                                    queryWrapper.eq(WarningFactorValue::getYear, year - 2);
//                                    queryWrapper.eq(WarningFactorValue::getMonth, 12);
//                                    break;
//                                case LAST_MONTH:
//                                    queryWrapper.eq(WarningFactorValue::getYear, year);
//                                    queryWrapper.eq(WarningFactorValue::getMonth, month - 1);
//                                    break;
//                            }
//                            WarningFactorValue factorValue = getOne(queryWrapper);
//                            if (factorValue != null){
//                                tempMap.put(specialCode, factorValue.getValue());
//                            }
//                        }
//                    }
//                    BigDecimal value = operationExpressionUtil.operationB(warningFactorExtension.getFormula(), tempMap, 6, BigDecimal.ROUND_HALF_UP);
//                    if (value != null){
//                        warningFactorValue.setValue(value);
//                        tempMap.put(warningFactorValue.getFactorCode(), warningFactorValue.getValue());
//                        warningFactorValue.setValueType(FORMULA_VALUE);
//                        warningFactorValues.add(warningFactorValue);
//                    }
//                }
//            }
//        }
//        return warningFactorValues;
//    }
//}
